from kubernetes import client, config
import logging

# 设置日志
logger = logging.getLogger(__name__)

# 创建 K8S 客户端
try:
    config.load_incluster_config()
    logger.info("Successfully loaded in-cluster Kubernetes config")
except config.ConfigException:
    try:
        config.load_kube_config()
        logger.info("Successfully loaded local kubeconfig")
    except config.ConfigException as e:
        logger.error(f"Failed to load Kubernetes config: {str(e)}")
        raise RuntimeError("Could not configure kubernetes python client")

# 创建 API 客户端实例
v1_core = client.CoreV1Api()
apps_v1 = client.AppsV1Api()
logger.info("Kubernetes API clients initialized successfully")